﻿#ifndef ELEMENTTREEITEM_H
#define ELEMENTTREEITEM_H
#include <QList>
#include <QVariant>
#include <QMap>
class ElementUiBase;
class ElementTreeItem
{
    //friend class ElementTreeModel;
public:
    /* {
        DisplayRole = 0,
        DecorationRole = 1,
        EditRole = 2,
        ToolTipRole = 3,
        StatusTipRole = 4,
        WhatsThisRole = 5,
        // Metadata
        FontRole = 6,
        TextAlignmentRole = 7,
        BackgroundRole = 8,
        ForegroundRole = 9,
        CheckStateRole = 10,
        // Accessibility
        AccessibleTextRole = 11,
        AccessibleDescriptionRole = 12,
        // More general purpose
        SizeHintRole = 13,
        InitialSortOrderRole = 14,
        // Internal UiLib roles. Start worrying when public roles go that high.
        DisplayPropertyRole = 27,
        DecorationPropertyRole = 28,
        ToolTipPropertyRole = 29,
        StatusTipPropertyRole = 30,
        WhatsThisPropertyRole = 31,
        // Reserved
        UserRole = 0x0100
    };*/
    ElementTreeItem();
    ~ElementTreeItem();
    // 返回位于父节点的第几行，顶级节点返回-1
    int rowOnParent() const;
    // 返回指定位置的子节的
    ElementTreeItem* child(int index);
    // 子节点数量
    inline auto childrenCount() const
        {return mChildren.size();}
    // 返回父节点
    inline ElementTreeItem* parent(){return mParent;}
    // 设置父节点为nullptr
    void setParentToNull();
    // 添加子节点
    bool appendChild(ElementTreeItem* child);
    bool insertChild(int index,ElementTreeItem* child);
    // 返回数据
    QVariant value(int dataRole) const;
    // 添加数据
    void setValue(int dataRole,const QVariant&v);
    void setValue(int dataRole,QVariant&&v);
    // 判断是否有
    inline bool have(int dataRole) const
        {return mValues.find(dataRole)!=mValues.end();}
    inline bool valuesCount(){
        return mValues.count();
    }
    inline bool isLeaf(){
        return  mChildren.size()==0;
    }
private:
    ElementTreeItem* mParent;
    QList<ElementTreeItem*> mChildren;
    QMap<int,QVariant> mValues;//
    ElementUiBase *mUi;
};

#endif // ELEMENTTREEITEM_H
